package com.ng.desktop.fpa.persistence;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.ng.desktop.fpa.model.FacturaDBF;
import com.ng.desktop.fpa.services.NGConfiguration;
import com.ng.framework.util.NGUtil;

@Repository("facturaPersistenceDBF")
public class FacturaPersistenceDBF extends NGDBFPersistence<FacturaDBF> {

	@Resource(name = "ngConfigurationBean")
	private NGConfiguration configurationBean;

	public List<FacturaDBF> getAllFactura() {

		return this.getObjectsFromDBF(configurationBean.getApplicationDBFPath() + "/facclit.dbf", new FacturaDBF());

	}

	public List<FacturaDBF> getAllFacturaByFecha(Date originalDate) {

		Date date = NGUtil.addTime(originalDate, Calendar.DAY_OF_MONTH, -1);

		List<FacturaDBF> facturasDBF = new ArrayList<FacturaDBF>();

		List<FacturaDBF> allFactura = this.getAllFactura();

		for (FacturaDBF facturaDBF : allFactura) {

			if (facturaDBF.getFecha() != null && facturaDBF.getFecha().after(date)
					&& !facturaDBF.getFecha().after(NGUtil.getNow())) {

				facturasDBF.add(facturaDBF);
			}
		}
		allFactura = null;

		return facturasDBF;
	}

}
